﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_BBSDeleteReplay]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_BBSDeleteReplay];
GO
CREATE PROCEDURE [dbo].[sproc_BBSDeleteReplay]
    @replay_id int
/*
======================================================
功能:    删除帖子的回复
参数:
    @replay_id int        :    回复的ID

======================================================
*/
AS
DECLARE @item_id int
SET @item_id =0
--得到回复所在的帖子ID
SELECT @item_id = item_id 
    FROM uds_bbs_replay
    WHERE replay_id = @replay_id
--删除回复
DELETE FROM uds_bbs_replay 
    WHERE replay_id = @replay_id
--更新此帖子的点击次数和回复次数以及最后回复人等
UPDATE uds_bbs_forumitem
    SET
    hit_times = hit_times -1,
    replay_times = replay_times -1,
    last_replayer=(select top 1 sender from uds_bbs_replay where item_id = @item_id order by send_time desc),
    last_replay_time=(select top 1 send_time from uds_bbs_replay where item_id = @item_id order by send_time desc)
    WHERE item_id = @item_id